home *** CD-ROM | disk | FTP | other *** search
- unit Array3U;
-
- interface
-
- uses
- WinProcs, WinTypes, Messages, SysUtils, Classes, Graphics, Controls,
- Forms, Dialogs, Grids, StdCtrls;
-
- type
- TArray3MainForm = class(TForm)
- ListBox1: TListBox;
- btnResizeArray: TButton;
- btnFillArray: TButton;
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure btnResizeArrayClick(Sender: TObject);
- procedure btnFillArrayClick(Sender: TObject);
- private
- MyArray: TList;
- procedure DisplayArray;
- end;
-
- var
- Array3MainForm: TArray3MainForm;
-
- implementation
-
- {$R *.DFM}
-
- procedure TArray3MainForm.FormCreate(Sender: TObject);
- begin
- MyArray := TList.Create;
- MyArray.Count := StrToInt(InputBox(
- 'Enter your array dimensions',
- 'Number of elements:', '10'));
- btnFillArray.Click; { Pretend to push the array filling button }
- DisplayArray
- end;
-
- procedure TArray3MainForm.FormDestroy(Sender: TObject);
- begin
- MyArray.Free;
- MyArray := nil
- end;
-
- procedure TArray3MainForm.btnResizeArrayClick(Sender: TObject);
- begin
- MyArray.Count := StrToInt(InputBox(
- 'Enter your new array dimensions',
- 'Number of elements:', '20'));
- DisplayArray
- end;
-
- procedure TArray3MainForm.btnFillArrayClick(Sender: TObject);
- var
- Loop: Integer;
- begin
- for Loop := 0 to Pred(MyArray.Count) do
- MyArray[Loop] := Pointer(Loop);
- DisplayArray
- end;
-
- procedure TArray3MainForm.DisplayArray;
- var
- Loop: Integer;
- begin
- with ListBox1, Items do
- begin
- BeginUpdate;
- try
- Clear;
- for Loop := 0 to Pred(MyArray.Count) do
- Add(IntToStr(Integer(MyArray[Loop])));
- ItemIndex := Pred(MyArray.Count)
- finally
- EndUpdate
- end
- end
- end;
-
- end.
-